﻿<!DOCTYPE html>
<html>
<head>
    <title>求助列表</title>
    <link href="/static/css/framework-font.css" rel="stylesheet"/>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <script src="/static/js/jquery.cookie.js"></script>
    <link href="/static/css/framework-theme.css" rel="stylesheet"/>
    <script src="/static/js/framework-ui.js"></script>
    <script src="/static/js/framework-clientdata.js"></script>
    <script src="/static/js/yii.js"></script>

    <!--引用layui弹框插件-->
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/layui.js"></script>

    <link href="/static/css/default/public.css" rel="stylesheet"/>
</head>
<body>
<style>
    .layui-btn{height: 30px;line-height: 30px;}
</style>

<style>
    .active{background-color: #00a104!important;
        border:1px solid #00a104!important;}
</style>
{if condition="$istype eq 0"}
<div class="container new_serach">
    <a class="btn btn-primary btn-sm active" href="{:URL('project/help/index')}" >求助列表</a>
    <a class="btn btn-primary btn-sm" href="{:URL('project/employ/index')}">服务状态审核</a>
</div>
{/if}


<div class="newtest">
    <div class=" new_serach">
        <form class="layui-form layui-col-md12 x-so" name="searchForm">
            <span> 求助人：</span>
            <div class="layui-inline layui-form">
                <select class="layui-select" lay-search="" name="account">
                    <option value="">全部</option>
                    {volist name="account" id="vo"}
                    <option value="{$vo.id}">{$vo.name}</option>
                    {/volist}
                </select>
            </div>

            <span> 状态：</span>
            <div class="layui-inline layui-form">
                <select class="layui-select" lay-search="" name="status">
                    <option value="">全部</option>
                    {volist name="status" id="vo"}
                    <option value="{$key}">{$vo}</option>
                    {/volist}
                </select>
            </div>

            <input type="hidden" name="istype" value="{$istype}">

            <button class="layui-btn serach_btn" type="button" ><i class="layui-icon">&#xe615;</i></button>
            <button class="layui-btn layui-btn-primary" type="reset">重置</button>
        </form>
    </div>

    <!--导入按钮-->
    <button type="button" class="layui-btn-sm layui-btn" id="test3" lay-event="upload" style="display: none" ></button>

    <div class="new_main">

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                {if condition="$istype eq 1"}
                <a class="layui-btn-sm layui-btn" lay-event="add" >添加</a>
                {/if}
                <a class="layui-btn-sm layui-btn layui-btn-danger" lay-event="getCheckLength">批量删除</a>
            </div>
        </script>


        <table class="layui-hide" id="demo" lay-filter="demo"></table>

        <script type="text/html" id="switchTpl">
            <!--启用禁用操作-->
            <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sexDemo" {{ d.status == 1 ? 'checked' : '' }}>
        </script>


        <script type="text/html" id="barDemo">

            {if condition="$istype eq 1"}
            <button class="layui-btn layui-btn-sm" lay-event="edit">编辑</button>
            {/if}

            <button class="layui-btn layui-btn-sm" lay-event="detail">查看详情</button>
            <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除</button>
        </script>

    </div>


</div>
<script src="/static/js/index.js"></script>
<script src="/static/js/indextab.js"></script>
<script src="/static/js/pace.min.js"></script>
<!--弹框js-->
<script src="/static/js/yii.js"></script>
<script>
    var showPage = "{$showPage}";
    var modal=new yii.modal();
    layui.use(['form','jquery','layer','laydate','table','upload'], function() { //独立版的layer无需执行这一句
        var $ = layui.jquery, layer = layui.layer,upload = layui.upload;;
        var form = layui.form;
        var laydate = layui.laydate;
        var table = layui.table //表格

        //日期范围
        laydate.render({
            elem: '#test6'
            , range: true
        });

        var url = "{:URL('project/Help/index')}";
        var detail = "{:URL('project/Help/detail')}";

        //搜索操作
        $('.serach_btn').click(function () {
            var data=$("form[name='searchForm']").serializeArray();
            var dataVal = {};
            $.each(data, function(i, item){
                dataVal[item.name] = item.value;
            });
            var where = dataVal;

            // var keyword = $('input[name="keyword"]').val();
            // var where = {keyword:keyword,status:status,id:pid};
            search(table,url,where)
        });

        //列表
        var data=$("form[name='searchForm']").serializeArray();
        var dataVal = {type:'list'};
        $.each(data, function(i, item){
            dataVal[item.name] = item.value;
        });
        var where = dataVal;

        var title = "权限列表";
        var cols = [[
            {type: 'checkbox', fixed: 'left'}
            ,{field: 'id', title: 'ID',  sort: true, fixed: 'left',width:80, align:'center'}
            ,{field: 'name', title: '求助人', align:'center'}
            ,{field: 'content', title: '求助内容', align:'center'}
            ,{field: 'addtime', title: '求助时间', align:'center'}
            ,{field: 'status', title: '状态', align:'center'}
            ,{fixed: 'right',title: '操作', width:500, align:'center', toolbar: '#barDemo'}
        ]];
        showlist(table,url,where,title,cols,0,10,'#demo','#toolbarDemo',showPage);
        $(".layui-laypage-skip").find("input").val(3 );
        $(".layui-laypage-btn").click();


        //监听行工具事件
        table.on('tool(demo)', function(obj) {
            var id = obj.data.id;
            switch (obj.event) {
                case 'del':
                    layer.confirm('是否确定操作?', function (index) {
                        let url = "{:URL('project/Help/del')}";
                        let where = {id: id};
                        publicDel(table, url, where, obj, index, 1);
                    });
                    break;
                case 'detail':
                    var showUrl = detail+"?id="+id;
                    showView(showUrl,"详情");
                    break;
                case 'edit':
                    let editView = "{:URL('project/Help/editView')}";
                    var showUrl = editView+"?id="+id;
                    showView(showUrl,"编辑");
                    break;
            }
        })


        function showView(showUrl,type){
            layer.open({
                type: 2,
                skin: 'layui-layer-demo', //样式类名
                area: ['700px','880px'],            //宽度450px,高自适应
                anim: 2,
                shadeClose: false, //开启遮罩关闭,
                maxmin: true,
                title: type,
                content:showUrl,
                btn:['确认','关闭'],
                yes: function (index,layero) {
                    var body = layer.getChildFrame('body', index);
                    var data = body.find("form[name='saveForm']").serializeArray();
                    // data.push({name: "plan_id", value: plan_id});
                    $.ajax({
                        type: "post",
                        url: "{:URL('project/help/save')}",
                        data: data,
                        dataType: "json",
                        success: function (data) {
                             layer.alert(data.msg);
                            if(data.code==0){
                                layer.close(index);
                                table.reload("demo"); 
                            }
                         
                            
                        }
                    });
                },
            });
        }


        //头工具栏事件
        table.on('toolbar(demo)', function(obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'add':
                    var showUrl = "{:URL('project/help/addView')}";
                    showView(showUrl,"添加");
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    var id=[];
                    for (var i = 0; i < data.length; i++) {
                        id[i] = data[i].id;
                    }
                    if(id.length==0){
                        layer.alert("请选择需操作的数据");return;
                    }

                    layer.confirm('是否确定操作?', function(index){
                        let url="{:URL('project/Help/del')}";
                        let where = {id:id};
                        publicDel(table,url,where,obj,index,1);
                    });
                    break;
            }
        });


        layui.form.render('select');
    });
</script>
</body>
</html>
